package com.ltmonitor.jt808.protocol;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.ltmonitor.util.StringUtil;

/** 
 * can总线数据上传
*/
public class JT_0705 implements IMessageBody
{
	protected Logger logger = Logger.getLogger(getClass());
	
	private short itemNum;
	
	private String recvTime;

	
	private List<CanDataItem>  canDataList = new ArrayList<CanDataItem>();
	

	public final byte[] WriteToBytes()
	{
		return null;
	}

	public final void ReadFromBytes(byte[] bytes)
	{
		MyBuffer buff = new MyBuffer(bytes);
		
		itemNum = buff.getShort();
		recvTime = buff.getBcdString(5);
		
		for(int k = 0; k < itemNum; k++)
		{
			CanDataItem ci = new CanDataItem();
			
			int tempId = buff.getInt();
			String strHex = Integer.toBinaryString(tempId);
			strHex = StringUtil.leftPad(strHex, 32, '0');
			
			ci.setChannel(Byte.parseByte(strHex.substring(0,1)));
			ci.setFrameType(Byte.parseByte(strHex.substring(1,2)));
			ci.setDataWay(Byte.parseByte(strHex.substring(2,3)));
			
			String strCanId = strHex.substring(3);
			ci.setCanId(Integer.valueOf(strCanId,2));
			ci.setCanData(buff.gets(8));
			canDataList.add(ci);
		}
	}
	

	public short getItemNum() {
		return itemNum;
	}

	public void setItemNum(short itemNum) {
		this.itemNum = itemNum;
	}

	public String getRecvTime() {
		return recvTime;
	}

	public void setRecvTime(String recvTime) {
		this.recvTime = recvTime;
	}

	public List<CanDataItem> getCanDataList() {
		return canDataList;
	}

	public void setCanDataList(List<CanDataItem> canDataList) {
		this.canDataList = canDataList;
	}
	

}